using System;
using System.Collections.Generic;
using System.Configuration;
using Needle.Core.Injection;

namespace Needle.Core.Configuration {
    /// <summary>
    /// The collection of injected properties
    /// </summary>
    public class PropertyElementCollection : NeedleElementCollection {
         
        /// <summary>
        /// Create a new element.
        /// </summary>
        protected override ConfigurationElement CreateNewElement() {
            return new PropertyElement();
        }

        /// <summary>
        /// gets the key of the property element (the name).
        /// </summary>
        protected override object GetElementKey(ConfigurationElement element) {
            return ((PropertyElement)element).Name;
        }

        /// <summary>
        /// The name of the item xml element.
        /// </summary>
        protected override string ElementName {
            get {
                return Element.Property;
            }
        }

        internal IList<IInjectionSite> GetInjectionSites(Type injectedType)
        {
            List<IInjectionSite> sites = new List<IInjectionSite>();
            foreach (PropertyElement property  in this)
            {
                sites.Add(property.GetInjectionSite(injectedType));
            }
            return sites.AsReadOnly();
        }
    }
}
